﻿

using Maticsoft.BLL;
using Maticsoft.DBUtility;
using Maticsoft.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class WebPage_Project_WeiKaishixiangmu : TeamBBasePage
{
    private string dataTime = DateTime.Today.ToString("yyyy-MM-dd");

    public Maticsoft.BLL.Order order = new Maticsoft.BLL.Order();
    public string sql = "";
    public string style = "";
    public string style1 = "";
    public string style2 = "";
    public string style3 = "";
    public Maticsoft.BLL.Team teams = new Maticsoft.BLL.Team();

    private void addProject(int id)
    {
        Maticsoft.Model.Team model = new Maticsoft.Model.Team();
        model = this.teams.GetModel(id);
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        this.pages = this.AspNetPager1.CurrentPageIndex;
        this.getDangqian();
    }

    private void delProject(int id)
    {
        if (this.isExist(id))
        {
            this.SetError("项目已成交，不能删除,删除失败");
        }
        else
        {
            this.teams.Delete(id);
            base.SetSuccess("删除成功");
        }
    }

    private void getDangqian()
    {
        int num;
        this.Session["sql"] = this.sqlWhere + this.sql;
        this.Literal1.Text = "<tr ><th width='40'>ID</th><th width='400'>项目名称</th><th width='80' nowrap>类别</th><th width='80' nowrap>排序</th><th width='100'>日期</th><th width='50'>成交</th><th width='60' nowrap>价格</th><th width='140'>操作</th></tr>";
        StringBuilder builder = new StringBuilder();
        Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
        List<Maticsoft.Model.Team> list = new List<Maticsoft.Model.Team>();
        list = this.teams.SearchTeam(this.AspNetPager1.PageSize, this.pages, "*", "order by Sort_order desc,id desc", this.sqlWhere + this.sql, out num);
        this.AspNetPager1.RecordCount = num;
        int num2 = 0;
        foreach (Maticsoft.Model.Team team in list)
        {
            if ((num2 % 2) != 0)
            {
                builder.Append("<tr>");
            }
            else
            {
                builder.Append("<tr class='alt'>");
            }
            num2++;
            builder.Append("<td>" + team.Id + "</a></td>");
            if (team.Team_type == "normal")
            {
                builder.Append(string.Concat(new object[] { "<td>[团购]\t<a class='deal-title' href='/team.aspx?id=", team.Id, "' target='_blank'>", team.Title, "</a></td>" }));
            }
            else if (team.Team_type == "seconds")
            {
                builder.Append(string.Concat(new object[] { "<td>[秒杀]\t<a class='deal-title' href='/team.aspx?id=", team.Id, "' target='_blank'>", team.Title, "</a></td>" }));
            }
            else if (team.Team_type == "goods")
            {
                builder.Append(string.Concat(new object[] { "<td>[热销]\t<a class='deal-title' href='/team.aspx?id=", team.Id, "' target='_blank'>", team.Title, "</a></td>" }));
            }
            builder.Append("<td nowrap>");
            Maticsoft.Model.Category model = new Maticsoft.Model.Category();
            model = category.GetModel(team.City_id);
            if (model != null)
            {
                builder.Append(model.Name);
            }
            else
            {
                builder.Append("全部城市");
            }
            builder.Append("<br/>");
            Maticsoft.Model.Category category3 = new Maticsoft.Model.Category();
            category3 = category.GetModel(team.Group_id);
            if (category3 != null)
            {
                builder.Append(category3.Name);
            }
            else
            {
                builder.Append("");
            }
            builder.Append("</td>");
            builder.Append("<td>" + team.Sort_order + "</td>");
            builder.Append(string.Concat(new object[] { "<td nowrap>", team.Begin_time, "<br/>", team.End_time, "</td>" }));
            builder.Append(string.Concat(new object[] { "<td nowrap>", team.Now_number, "/", team.Min_number, "</td>" }));
            builder.Append(string.Concat(new object[] { "<td nowrap><span class='money'>\x00a5</span>", team.Market_price, "<br/><span class='money'>\x00a5</span>", team.Team_price, "</td>" }));
            builder.Append("<td class='op' nowrap>");
            builder.Append("<a class='ajaxlink' href='/ajax/manage.aspx?action=teamdetail&id=" + team.Id + "'>详情</a>｜");
            builder.Append("<a href='Project_BianjiXiangmu.aspx?id=" + team.Id + "'>编辑</a>｜");
            builder.Append(string.Concat(new object[] { "<a href='Project_DangqianXiangmu.aspx?remove=", team.Id, "&pagenum=", this.pages, "'  ask='确定删除本项目吗？' >删除</a>" }));
            builder.Append("</td>");
            builder.Append("</tr>");
        }
        this.Literal2.Text = builder.ToString();
    }

    public bool isExist(int id)
    {
        bool flag = false;
        DataSet set = DbHelperSQL.Query("select o.*,d.id from orderdetail as d,[Order] as o where d.Teamid='" + id + "' and d.Order_id=o.Id and o.State='pay'");
        if ((this.order.GetModelList("Team_id=" + id + " and State='pay'").Count > 0) || (set.Tables[0].Rows.Count > 0))
        {
            flag = true;
        }
        return flag;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "program";
        if (base.Request.QueryString["remove"] != null)
        {
            this.delProject(int.Parse(base.Request.QueryString["remove"].ToString()));
        }
        if (base.Request.QueryString["add"] != null)
        {
            this.addProject(Convert.ToInt32(base.Request.QueryString["add"].ToString()));
        }
        if (base.Request.QueryString["team_type"] == null)
        {
            this.style = "current";
        }
        else
        {
            string str = base.Request.QueryString["team_type"].ToString();
            if (str != null)
            {
                if (!(str == "normal"))
                {
                    if (str == "seconds")
                    {
                        this.style2 = "current";
                    }
                    else if (str == "goods")
                    {
                        this.style3 = "current";
                    }
                }
                else
                {
                    this.style1 = "current";
                }
            }
            this.sqlWhere = "Begin_time >GetDate() and  Team_type='" + base.Request.QueryString["team_type"].ToString().Replace("'", "''") + "' ";
        }
        if (base.Request["pagenum"] != null)
        {
            this.sqlWhere = this.Session["sql"].ToString();
            this.pages = Convert.ToInt32(base.Request["pagenum"]);
        }
        this.getDangqian();
    }

    public int pages
    {
        get
        {
            if (this.ViewState["pages"] != null)
            {
                return Convert.ToInt32(this.ViewState["pages"].ToString());
            }
            return 1;
        }
        set
        {
            this.ViewState["pages"] = value;
        }
    }

    public string sqlWhere
    {
        get
        {
            if (this.ViewState["sqlWhere"] != null)
            {
                return this.ViewState["sqlWhere"].ToString();
            }
            return " Begin_time >GetDate()";
        }
        set
        {
            this.ViewState["sqlWhere"] = value;
        }
    }
}


